package com.uboxol.example.tengu.api;

import com.uboxol.cloud.tengu.common.server.annotation.ApiMapping;
import com.uboxol.cloud.tengu.common.server.annotation.TenguApi;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import java.util.Date;

/**
 * model: tengu
 * 所有接口统一设置,类下面所有接口都会注册,并需要授权
 * @author liyunde
 * @since 2019/9/10 17:01
 */
@TenguApi(permission = true)
@RestController
public class UnifiedApiController {

    @GetMapping(value = "story.first.get")
    public StoryResult getStory() {
        StoryResult result = new StoryResult();
        result.setId(1L);
        result.setName("这是一个故事");
        return result;
    }

    @PostMapping(value = "first.goods.add")
    public Object addGoods(GoodsParam param) {
        return param;
    }

    @Data
    public static class GoodsParam {
        @NotEmpty(message = "不能为空") // 支持JSR-303校验
        private String goodsRemark;
    }


    // 请求参数
    @Data
    public static class StoryParam {
        @ApiModelProperty(value = "故事ID", example = "111")
        private int id;

        @ApiModelProperty(value = "故事名称", required = true, example = "白雪公主")
        private String name;
    }

    // 返回结果
    @Data
    public static class StoryResult {
        @ApiModelProperty(value = "故事ID", example = "1")
        private Long id;

        @ApiModelProperty(value = "故事名称", example = "一千零一夜")
        private String name;

        @ApiModelProperty(value = "创建时间", example = "2019-04-14 19:02:12")
        private Date gmtCreate;
    }
}
